﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThietBiSo.LinQDB;
using ThietBiSo.Models;
namespace ThietBiSo.Controllers
{
    public class AdminController : ApplicationController
    {
        //
        // GET: /Admin/
        private _24hmuaonlineDataContext context = new _24hmuaonlineDataContext();
        private Admin ad = new Admin();
        private MAdmin mad = new MAdmin();
        public ActionResult quantri()
        {
            return View();
        }

        public ActionResult index()
        {
            return View();
        }
        //public Admin GetAdmin()
        //{          

        //    if (Session["HoTenAdmin"] != null)
        //    {
        //        ad =(Admin)Session["HoTenAdmin"];

        //        return ad;
        //    }
        //    return null;
        //}
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult ChangePassword()
        {

            ad = (Admin)Session["HoTenAdmin"];
            ViewData["AdminInfo"] = ad;            
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ChangePassword(int userId, string username, string passwordNew, string hoten)
        {
            ad = (Admin)Session["HoTenAdmin"];
            try
            {
                
                Admin user1 = mad.getUserById(userId);
                user1.Username = username;
                user1.Password = passwordNew;
                user1.HoTen = hoten;
                mad.SaveChange();
            }
            catch { }

            ViewData["AdminInfo"] = ad;
            ViewData["Message"] = "Thông tin đã được đổi thành công!";            
            return View();
        }


    }
}
